package com.road.yishi.mina.codec.protobuf;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;

/**
 * ProtocolCodecFactory
 */
public class ProtobufCodecFactory implements ProtocolCodecFactory {

	private static ProtocolEncoderAdapter ENCODER_INSTANCE;
	private static CumulativeProtocolDecoder DECODER_INSTANCE;

	public ProtobufCodecFactory() throws Exception {
		// if (VerifyMgr.isLoadCore()) {
		// Log.error("Load Core...");
		// Class<?> class1 =
		// VerifyMgr.findClass("com.road.yishi.mina.codec.protobuf.ProtobufEncoder");
		// ENCODER_INSTANCE = (ProtocolEncoderAdapter) class1.newInstance();
		//
		// Class<?> class2 =
		// VerifyMgr.findClass("com.road.yishi.mina.codec.protobuf.ProtobufDecoder");
		// DECODER_INSTANCE = (CumulativeProtocolDecoder) class2.newInstance();
		// }
		ENCODER_INSTANCE = new ProtobufEncoder();
		DECODER_INSTANCE = new ProtobufDecoder();
	}

	public CumulativeProtocolDecoder getDecoder(IoSession session) throws Exception {
		return DECODER_INSTANCE;
	}

	public ProtocolEncoderAdapter getEncoder(IoSession session) throws Exception {
		return ENCODER_INSTANCE;
	}

}
